<template>
	<view class="buy-box">
		<!-- <view class="buy-title">
			历史采购
		</view> -->
		<view class="buy-list" v-for="(item,index) in mySupplyArr" :key="index">
			<view class="buy-top">
				<view class="buy-top-title">
					{{item.name}}
				</view>
				<view class="buy-top-cont">
					<view class="buy-top-cont-lt">
						采购数量：<text>{{item.buyNum}}</text>
					</view>
					<view class="buy-top-cont-rt">
						联系电话：<text>{{item.userTel}}</text>
					</view>
				</view>
				<view class="buy-top-bt">
					<!-- <view class="buy-top-bt-tel">
						<text>0</text>人联系
					</view> -->
					<view class="buy-top-bt-date">
						{{item.endTime==null?'长期采购':'截止到:'+item.endTime}}
					</view>
				</view>
			</view>
			<view class="buy-btm">
				<!-- icon="trash" iconColor="#2684ff" -->
				<u-button text="删除"  :customStyle="customStyle1"  color="red" :plain="true" @click="deleteInfo(item,index)"></u-button>
				<u-button text="编辑" :customStyle="customStyle2" color="#2684ff" :plain="true" @click="editInfo(item,index)"></u-button>
			</view>
			
			
		</view>
		<u-modal :show="modalShow" title="确定删除采购需求?" closeOnClickOverlay showCancelButton @confirm="confirm" @cancel="modalShow=false" @close="modalShow=false"></u-modal>
	</view>
</template>

<script>
	export default {
		// props:{
		// 	mySupplyArr: {
		// 		type: Array,
		// 		default () {
		// 			return [] //['gif']
		// 		}
		// 	},
		// },
		data() {
			return {
				customStyle1: {
					border:"none",
					// fontSize:'30upx'
				},
				customStyle2: {
					border:"none",
					// fontSize:'30upx'
				},
				pageNo:1,
				pageSize:10,
				openId:'',
				name:'',
				listArr:[],
				modalShow:false,
				deleteId:'',
				mySupplyArr:[]
			};
		},
		mounted(){
			let openId = uni.getStorageSync('openId')
			console.log("openId", openId)
			this.openId=openId.openid
			this.mySupplyArr=[]
			this.querySupplyList()
		},
		methods:{
			lower(){
				// console.log(1)
				console.log("找供应")
				if (this.pageNo * 10 > this.total) {
					uni.showToast({
						title: '没有更多数据',
						icon: 'none'
					})
				}
				this.pageNo++
				this.querySupplyList()
			},
			// 我的供应商列表数据
			querySupplyList(){
				this.$api.queryMySupplyListsByOpenId(this.name,this.openId,this.pageNo,this.pageSize).then(res => {
					console.log(res)
					
					if (res.success) {
						this.mySupplyArr =[...this.mySupplyArr, ...res.result.records]
						this.total = res.result.total
					}
				})
			},
			editInfo(item,index){
				console.log(item,index)
				this.$api.queryMyHistorySupplyListsById(item.id).then(res=>{
					console.log(res)
					if(res.success){
						this.$store.commit('setMySupInfo', res.result)
						// this.$api.queryMySupplyListsByOpenId(this.name,this.openId,this.pageNo,this.pageSize).then(res => {
						// 	console.log(res)
							
						// 	if (res.success) {
						// 		this.mySupplyArr =res.result.records
						// 		this.total = res.result.total
						// 	}
						// })
						uni.navigateTo({
							url: '/pagesBusiness/supply/supply'
						})
					}
				})
				
			},
			deleteInfo(item,index){
				console.log(item,index)
				this.modalShow=true
				this.deleteId=item.id
			},
			confirm(){
				
				this.$api.deleteMySupplyListsById(this.deleteId).then(res => {
					console.log(res)
					if (res.success) {
						uni.showToast({
							title:res.result
						})
						this.modalShow=false
						// this.$emit('deleteSupplyReset',1)
						this.myBuyArr=[]
						this.total = 0
						this.pageNo=1
						this.$api.queryMySupplyListsByOpenId(this.name,this.openId,this.pageNo,this.pageSize).then(res => {
							console.log(res)
							
							if (res.success) {
								this.mySupplyArr =res.result.records
								this.total = res.result.total
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.buy-box{
		padding: 20upx;
		background: #f6f6f6;
		.buy-title{
			font-weight: bold;
		}
		.buy-list{
			margin-top: 30upx;
			background: white;
			border-radius: 10upx;
			position: relative;
			padding: 20upx;
			.buy-top{
				border-bottom: 1px solid #f4f4f4;
				padding-bottom: 20upx;
				.buy-top-title{
					font-size: 36upx;
					font-weight: bold;
				}
				.buy-top-cont{
					font-size: 32upx;
					color: #666666;
					display: flex;
					justify-content: space-between;
					margin-top: 20upx;
				}
				.buy-top-bt{
					display: flex;
					font-size: 28upx;
					margin-top: 20upx;
					color: #999999;
					.buy-top-bt-date{
						// margin-left: 10upx;
					}
				}
			}
		
			.buy-btm{
				display: flex;
				margin-top: 20upx;
				.buy-btn1{
					border: none;
				}
			}
		
		}
	}
</style>
